package com.example.hotelmanagement.rest;

import com.example.hotelmanagement.common.pojo.CommonResult;
import com.example.hotelmanagement.common.pojo.PageResult;
import com.example.hotelmanagement.domain.entity.Room;
import com.example.hotelmanagement.domain.vo.RoomPageReqVo;
import com.example.hotelmanagement.service.RoomService;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * TODO
 *
 * @author chenhetao
 * @version 1.0
 * @className RoomController
 * @packageName com.example.hotelmanagement.rest
 * @date 2023/6/10 17:26
 */
@RestController
@RequestMapping("room")
public class RoomController {
    /**
     * 服务对象
     */
    @Resource
    private RoomService roomService;

    /**
     * 分页查询
     *
     * @param room 筛选条件
     * @return 查询结果
     */
    @PostMapping("/page")
    public CommonResult<PageResult<Room>> queryByPage(@RequestBody RoomPageReqVo room) {
        return CommonResult.success(roomService.queryByPage(room));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    public CommonResult<Room> queryById(@PathVariable("id") Long id) {
        return CommonResult.success(roomService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param room 实体
     * @return 新增结果
     */
    @PostMapping
    public CommonResult<Room> add(@RequestBody Room room) {
        return CommonResult.success(roomService.insert(room));
    }

    /**
     * 编辑数据
     *
     * @param room 实体
     * @return 编辑结果
     */
    @PutMapping
    public CommonResult<Room> edit(@RequestBody Room room) {
        return CommonResult.success(roomService.update(room));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public CommonResult<Boolean> deleteById(@RequestParam Long id) {
        return CommonResult.success(roomService.deleteById(id));
    }

}